home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 4 / The 640 Meg Shareware Studio CD-ROM Volume IV (Data Express)(1994).ISO / clang / cenvid.zip / BATTMEM.BAT < prev    next >
DOS Batch File  |  1993-04-12  |  6KB  |  177 lines

  1. @echo off
  2. REM Battmem.bat - Display status saved in battery-backed memory registers.
  3. REM               This examples programs displays how to use CEnvi to read
  4. REM               data from hardware ports, and how to manipulate bits within
  5. REM               a byte.
  6.  
  7. ECHO These are values read from battery-operated memory:
  8. cenvi %0.bat
  9. GOTO CENVI_EXIT
  10.  
  11. #define  CLOCK_ADDRESS_REG    0x70  // put address to read here
  12. #define  CLOCK_READ_REG       0x71  // read value from address
  13. #define  BLANK_LINE           printf("\n")
  14.  
  15. BLANK_LINE
  16. /*****************************************************/
  17. /* SHOW ERRORS THAT MAY OCCUR IN THE DIAGNOSTIC BYTE */
  18. /*****************************************************/
  19. #define  DIAGNOSTIC_REG_ADDRESS  0x0E
  20. #define  DIAG_BYTES_UNUSED       0x03
  21. #define  DATETIME_ERROR          0x04
  22. #define  HARD_DRIVE_ERROR        0x08
  23. #define  MEMSIZE_ERROR           0x10
  24. #define  BAD_CONFIG_BYTE         0x20
  25. #define  CHECKSUM_ERROR          0x40
  26. #define  DEAD_CLOCK_BATTERY      0x80
  27.  
  28. diag = ReadByte(DIAGNOSTIC_REG_ADDRESS) & ~DIAG_BYTES_UNUSED
  29. if ( 0 == diag )
  30.    printf("No errors in the Diagnostic Byte Structure.\n")
  31. else {
  32.    if ( diag & DATETIME_ERROR )
  33.       printf("Date or time incorrect!\a\n")
  34.    if ( diag & HARD_DRIVE_ERROR )
  35.       printf("Hard drive or controler error!\a\n")
  36.    if ( diag & MEMSIZE_ERROR )
  37.       printf("Memory size incorrect!\a\n")
  38.    if ( diag & BAD_CONFIG_BYTE )
  39.       printf("Configuration byte is incorrect!\a\n")
  40.    if ( diag & CHECKSUM_ERROR )
  41.       printf("Checksum incorrect!\a\n")
  42.    if ( diag & DATETIME_ERROR )
  43.       printf("Realtime battery clock is dead!\a\n")
  44. }
  45.  
  46. BLANK_LINE
  47. /*******************************/
  48. /* STATUS AT SYSTEM POWER DOWN */
  49. /*******************************/
  50. #define  POWERDOWN_REG     0x0F
  51. printf("Status at system powerdown = %d\n",ReadByte(POWERDOWN_REG))
  52.  
  53.  
  54. BLANK_LINE
  55. /***********************************/
  56. /* STATUS OF FIRST TWO DISK DRIVES */
  57. /***********************************/
  58. #define  DRIVETYPE_REG     0x10
  59. DriveTypes = ReadByte(DRIVETYPE_REG)
  60. printf("The first floppy drive is type: %s\n", DriveDescription(Bits(DriveTypes,4,4)) )
  61. printf("The second floppy drive is type: %s\n", DriveDescription(Bits(DriveTypes,0,4)) )
  62.  
  63. DriveDescription(type)
  64. {
  65.    switch( type ) {
  66.       case 0
  67.          description = "Not Installed"
  68.          break
  69.       case 1
  70.          description = "5-1/4, 320/360K"
  71.          break
  72.       case 2
  73.          description = "5-1/4, 1.2 meg"
  74.          break
  75.       case 3
  76.          description = "3-1/2, 720K"
  77.          break
  78.       case 4
  79.          description = "3-1/2, 1.44 meg"
  80.          break
  81.       default
  82.          sprintf(description,"Unknown drive type %d",type)
  83.          break
  84.    }
  85.    return(description)
  86. }
  87.  
  88.  
  89. BLANK_LINE
  90. /***************************************/
  91. /* SHOW TYPES OF FIRST TWO HARD DRIVES */
  92. /***************************************/
  93. #define  HARD_DRIVE_1_REG     0x11
  94. #define  HARD_DRIVE_2_REG     0x12
  95. printf("Hard drive 1 is type %d\n",ReadByte(HARD_DRIVE_1_REG))
  96. printf("Hard drive 2 is type %d\n",ReadByte(HARD_DRIVE_2_REG))
  97.  
  98.  
  99. BLANK_LINE
  100. /**********************************/
  101. /* SHOW CONFIGURATION INFORMATION */
  102. /**********************************/
  103. #define  CONFIGURATION_REG    0x14
  104. #define  NO_DRIVE_OFFSET      0
  105. #define  COPROCESSOR_OFFSET   1
  106. #define  HARDDRIVE_ERROR_OFF  3
  107. #define  VIDEO_STARTUP_OFF    4
  108. #define  VIDEO_STARTUP_COUNT  2
  109. #define  DISK_DRIVE_COUNT_OFF 6
  110. #define  DISK_DRIVE_COUNT_NUM 2
  111. config = ReadByte(CONFIGURATION_REG)
  112. printf("At lease 1 disk drive is%s installed.\n",Bits(config,NO_DRIVE_OFFSET,1) ? "" : " NOT" )
  113. printf("Math coprocessor is%s installed.\n",Bits(config,COPROCESSOR_OFFSET,1) ? "" : " NOT" )
  114. if Bits(config,HARDDRIVE_ERROR_OFF,1)
  115.    printf("Hard drive or controller error.\n")
  116. printf("Video mode at startup is: ")
  117. switch( Bits(config,VIDEO_STARTUP_OFF,VIDEO_STARTUP_COUNT) ) {
  118.    case 0      printf("unknown.\n")                   break
  119.    case 1      printf("CGA/EGA/VGA, 40 columns.\n")   break
  120.    case 2      printf("CGA,EGA,CGA, 80 columns.\n")   break
  121.    case 3      printf("MDA/Hercules, 80 columns\n")   break
  122. }
  123. printf("Number of disk drives = %d.\n",Bits(config,DISK_DRIVE_COUNT_OFF,DISK_DRIVE_COUNT_NUM))
  124.  
  125.  
  126. BLANK_LINE
  127. /***********************************************/
  128. /* SHOW MAIN MEMORY AND EXPANSION MEMORY SIZES */
  129. /***********************************************/
  130. #define  MEM_SIZE_REG         0x15
  131. #define  EXPANSION_MEM_REG    0x17
  132. #define  EXPANSION2_REG       0x30
  133. printf("Main memory size = %d K-bytes\n",ReadWord(MEM_SIZE_REG))
  134. printf("Expansion board's main memory size = %d K-bytes\n",ReadWord(EXPANSION_MEM_REG))
  135. printf("Expansion memory size = %d K-bytes\n",ReadWord(EXPANSION2_REG))
  136.  
  137.  
  138. BLANK_LINE
  139. /***************************/
  140. /* TIME, DATE, AND CENTURY */
  141. /***************************/
  142. #define  CENTURY_REG       0x32
  143. #define  CLOCK_STATUS_REG  0x0B
  144. century = ReadByte(CENTURY_REG)
  145. printf("Century is: %d%d00\n",Bits(century,4,4),Bits(century,0,4))
  146. clock = ReadByte(CLOCK_STATUS_REG)
  147. printf("Daylight savings time is%s in effect.\n",Bits(clock,0,1) ? "" : " not" )
  148. printf("Time is kept in %d hour format.\n",Bits(clock,1,1) ? 24 : 12 )
  149.  
  150.  
  151. BLANK_LINE
  152. /******************************************/
  153. /* UTILITY FUNCTIONS USED IN THIS PROGRAM */
  154. /******************************************/
  155.  
  156. Bits(ByteValue,BitOffset,BitCount)
  157.    // return specific bits in a byte, and shift them to the right.
  158. {
  159.    // clear all bits above BitCount
  160.    for ( mask = 0, i = 0; i < BitCount; i++ )
  161.       mask |= 1 << i
  162.    return((ByteValue >> BitOffset) & mask)
  163. }
  164.  
  165. ReadByte(RegisterAddress)
  166. {
  167.    outport(CLOCK_ADDRESS_REG,RegisterAddress)
  168.    return(inport(CLOCK_READ_REG))
  169. }
  170.  
  171. ReadWord(RegisterAddress)
  172. {
  173.    return( ReadByte(RegisterAddress) | ( ReadByte(RegisterAddress+1) << 8 ) )
  174. }
  175.  
  176. :CENVI_EXIT
  177.